﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_official_people
	/// </summary>
	public partial class oa_official_people
	{
		public oa_official_people()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("AID", "oa_official_people"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int AID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_official_people");
			strSql.Append(" where AID=@AID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@AID", MySqlDbType.Int32)
};
			parameters[0].Value = AID;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_official_people model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_official_people(");
			strSql.Append("ID,PropleCode,PropleName,CreatePeopleCode,HandleStatus,HandleInfo,HandleDate)");
			strSql.Append(" values (");
			strSql.Append("@ID,@PropleCode,@PropleName,@CreatePeopleCode,@HandleStatus,@HandleInfo,@HandleDate)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32,11),
					new MySqlParameter("@PropleCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@PropleName", MySqlDbType.VarChar,20),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@HandleStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@HandleInfo", MySqlDbType.VarChar,200),
					new MySqlParameter("@HandleDate", MySqlDbType.DateTime)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.PropleCode;
			parameters[2].Value = model.PropleName;
			parameters[3].Value = model.CreatePeopleCode;
			parameters[4].Value = model.HandleStatus;
			parameters[5].Value = model.HandleInfo;
			parameters[6].Value = model.HandleDate;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_official_people model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_official_people set ");
			strSql.Append("ID=@ID,");
			strSql.Append("PropleCode=@PropleCode,");
			strSql.Append("PropleName=@PropleName,");
			strSql.Append("CreatePeopleCode=@CreatePeopleCode,");
			strSql.Append("HandleStatus=@HandleStatus,");
			strSql.Append("HandleInfo=@HandleInfo,");
			strSql.Append("HandleDate=@HandleDate");
			strSql.Append(" where AID=@AID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32,11),
					new MySqlParameter("@PropleCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@PropleName", MySqlDbType.VarChar,20),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@HandleStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@HandleInfo", MySqlDbType.VarChar,200),
					new MySqlParameter("@HandleDate", MySqlDbType.DateTime),
					new MySqlParameter("@AID", MySqlDbType.Int32,11)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.PropleCode;
			parameters[2].Value = model.PropleName;
			parameters[3].Value = model.CreatePeopleCode;
			parameters[4].Value = model.HandleStatus;
			parameters[5].Value = model.HandleInfo;
			parameters[6].Value = model.HandleDate;
			parameters[7].Value = model.AID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int AID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_official_people ");
			strSql.Append(" where AID=@AID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@AID", MySqlDbType.Int32)
};
			parameters[0].Value = AID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string AIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_official_people ");
			strSql.Append(" where AID in ("+AIDlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_official_people GetModel(int AID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,AID,PropleCode,PropleName,CreatePeopleCode,HandleStatus,HandleInfo,HandleDate from oa_official_people ");
			strSql.Append(" where AID=@AID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@AID", MySqlDbType.Int32)
};
			parameters[0].Value = AID;

			becom.Model.oa_official_people model=new becom.Model.oa_official_people();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["AID"]!=null && ds.Tables[0].Rows[0]["AID"].ToString()!="")
				{
					model.AID=int.Parse(ds.Tables[0].Rows[0]["AID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["PropleCode"]!=null && ds.Tables[0].Rows[0]["PropleCode"].ToString()!="")
				{
					model.PropleCode=ds.Tables[0].Rows[0]["PropleCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PropleName"]!=null && ds.Tables[0].Rows[0]["PropleName"].ToString()!="")
				{
					model.PropleName=ds.Tables[0].Rows[0]["PropleName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreatePeopleCode"]!=null && ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString()!="")
				{
					model.CreatePeopleCode=ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["HandleStatus"]!=null && ds.Tables[0].Rows[0]["HandleStatus"].ToString()!="")
				{
					model.HandleStatus=int.Parse(ds.Tables[0].Rows[0]["HandleStatus"].ToString());
				}
				if(ds.Tables[0].Rows[0]["HandleInfo"]!=null && ds.Tables[0].Rows[0]["HandleInfo"].ToString()!="")
				{
					model.HandleInfo=ds.Tables[0].Rows[0]["HandleInfo"].ToString();
				}
				if(ds.Tables[0].Rows[0]["HandleDate"]!=null && ds.Tables[0].Rows[0]["HandleDate"].ToString()!="")
				{
					model.HandleDate=DateTime.Parse(ds.Tables[0].Rows[0]["HandleDate"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,AID,PropleCode,PropleName,CreatePeopleCode,HandleStatus,HandleInfo,HandleDate ");
			strSql.Append(" FROM oa_official_people ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_official_people";
			parameters[1].Value = "AID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

